@extends('admin.adminbase')
@section('content')


	<section class="hbox stretch">
		@include("admin.public.left")

		<aside>
			<section class="vbox">

				<header class="header bg-white b-b clearfix">
					<form class="talbe-search" method="get" action="">
						<div class="row m-t-sm">
							<div class="col-sm-12 m-b-xs">
								<div class="btn-group" role="group">
									<strong style="line-height:30px;">编辑节点</strong>
								</div>
								<div class="btn-group pull-right">
									<a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
										<i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
									</a>
								</div>
							</div>
						</div>
					</form>
				</header>
				<section class="scrollable  wrapper w-f">
					<section class="panel panel-default ">
						<div class="row m-l-none m-r-none bg-light lter">
							<div class="container" style="padding: 20px 0px">
								<form id="formclass" class="form-horizontal" style="padding-top: 15px;">
									<input type="hidden" name="_method" value="PUT">
									{!! csrf_field() !!}
									<div class="form-group">
										<label class="col-sm-3 control-label">父节点<span class="red">*</span></label>
										<div class="col-sm-4 ">
											<select class="form-control input-sm" name="nid">
                                                <option value="0" selected="">顶级节点</option>
                                                @foreach($res as $v)
                                                    <option value="{{$v->id}}" @if($one->nid==$v->id) selected @endif>{{$v->title}} </option>
                                                @endforeach
                                            </select>
										</div>
									</div>
									<input type="password" style="visibility: hidden;" >
									<div class="form-group">
                                        <label class="col-sm-3 control-label">节点<span class="red">*</span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="node" value="{{isset($one->node) ? $one->node : '' }}"
                                                   placeholder="请输入节点">
                                        </div>
                                    </div>
									<div class="form-group">
                                        <label class="col-sm-3 control-label">名称<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="title" value="{{isset($one->title) ? $one->title : '' }}"
                                                   placeholder="请输入名称">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">状态<span class="red">*</span></label>
                                        <div class="col-sm-4">
                                            <input type="radio" id="status1" name="status" value="{{\App\Http\Util\Status::ON}}" <?php if(\App\Http\Util\Status::getLabel($one->status) == "启用"): ?> checked <?php endif; ?>>
                                            <label for="status1">启用</label>
                                            <input type="radio" id="status0" name="status" value="{{\App\Http\Util\Status::OFF}}" <?php if(\App\Http\Util\Status::getLabel($one->status) == "禁用"): ?> checked <?php endif; ?>>
                                            <label for="status0">禁用</label>
                                        </div>
                                    </div>
									<div class="form-group">
										<label class="col-sm-3 control-label"></label>
										<div class="col-sm-2 ">
											<button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
										    <input type="checkbox" id="back">
                                            <label for="back">返回列表</label>
										</div>
									</div>
								</form>
							</div>
						</div>

					</section>
				</section>


			</section>
		</aside>
	</section>
@endsection
@section('addscript')
	<script>
		$(function(){
			$("#formclass").submit(function(){
                var nid=$("[name=nid]").val();
                var node=$("[name=node]").val();
                var title=$("[name=title]").val();
                var status=$("[name=status]:checked").val();
                var back=$("#back").is(':checked');
                if(nid==""){
                    layer.alert("父节点不得为空！");
                    return false;
                }
                $.ajax({
                    url:"{{ url('admin/node/edit/'.$one->id) }}",
                    type:"post",
                    dataType:"json",
                    data:{
                        nid:nid,
                        node:node,
                        title:title,
                        status:status
                    },
                    success:function(data){
                        if(data.success){
                            layer.alert(data.msg,function(){
                                if (back) {
                                    location.href="{{url('admin/node')}}";
                                } else {
                                    location.reload();
                                }
                            });
                        }
                        else{
                            layer.alert(data.msg);
                        }
                    }
                })
                return false;
			})


		});
	</script>
@endsection
